package com.wangfei.service;

import com.wangfei.entity.User;
import com.wangfei.entity.UserAddress;
import com.wangfei.mapper.UserAddressMapper;
import com.wangfei.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserAddressMapper userAddressMapper;

    public User getById(int id) {
        return userMapper.getById(id);
    }

    public List<User> getList(User user) {
        return userMapper.getList(user);
    }

    public void insert(User user) {
        userMapper.insert(user);
    }

    public void withUserAddress(User user) {
        List<Integer> user_ids = List.of(user.getId());
        List<UserAddress> userAddressList = userAddressMapper.getListByInUserId(user_ids, 1);
        if (!userAddressList.isEmpty()) {
            user.setUser_address(userAddressList);
        }
    }
}
